  var object={};
  var totalPage=1; 
  var page=1;
  var information={};
  var chooseId;
  var insertid;
$(function(){
  var endId=[];
  var insertid;
  var deleteid;
  requestRefer();//已提交数据
  //跳转到详情界面 
  $(document).on("click",".detail",function(){
	  var id= $(this).attr("data-id");
		var menuId=$("#menu-container").attr("menu-id");
		window.location.href = '../information/subDetailInfo.jsp?menuId='+menuId+'&detailId=' + id;
  });
  //添加责任人
  $("#Part").click(function(){
		$('#myPart').modal('show');
		requestStructucre();
	});
  //移除责任人
  $("#removeCho").click(function(){
		 $("input[name='Check']:checked").each(function () {
			$(this).parent().remove();	          
	     });
	})
	//移除所以责任人
	$("#removeAll").click(function(){
		$("#addRequest").find("ul").html("");
		
	})
//责任人数据请求
function requestStructucre()
{	var url="getStructucreLevel.do";//责任人地址
	var data={};
	var object={};
	YuXi.util.get(url,data,function(data){
		if(data.status){
			util.tree.start(data.object,$("#test-select"));
			$("#test-select").treeMultiselect({ enableSelectAll: true, sortable: true });
		}
	},function(){
		
	});//请求数据
	
	/*  var s={"status":true,"msg":"获取监狱部门等级成功","object":[{"id":37,"name":"监狱","superId":0,"level":2},{"id":38,"name":"科室","superId":37,"level":3},{"id":41,"name":"一分监区","superId":38,"level":4},{"id":43,"name":"一科室","superId":38,"level":4},{"id":39,"name":"一监区","superId":37,"level":3},{"id":42,"name":"一分监区","superId":39,"level":4},{"id":40,"name":"二监区","superId":37,"level":3},{"id":44,"name":"科一","superId":40,"level":4}],"subTime":1469453325148,"subType":"获取操作"};
	*/  //调用js
}
//责任人选中后的确定按钮
  function surePart()
  {
  	alert("surePart");
  	 var item=$(".ui-sortable .item");
       $("#node").find(".label1").html("");
       var pearson="";
       for(var i=0;i<item.length;i++)
       {
         firt=item[i].firstChild;
         if(i==item.length-1)
         {
           pearson+=firt.nextSibling.nodeValue;
         }
         else
         {
           pearson+=firt.nextSibling.nodeValue+",";

         }
         html="<span class='parsbox'><span  class='glyphicon glyphicon-user' aria-hidden='true'></span>"+firt.nextSibling.nodeValue+"&nbsp;&nbsp;</span></span>"
         $(".label1").append(html);
       }
       $('#myPart').modal('hide');
  	
  }
  //参与人摸态框，确定按钮
	$("#surePart").click(function(){
		$(".label1").html("");
		$("input[name='Check']").each(function(){
			var html="<span class='parsbox'><span  class='glyphicon glyphicon-user' aria-hidden='true' ></span><span class='select-data-user' data-id="+$(this).attr("data-id")+">"+$(this).val()+"</span>&nbsp;&nbsp;<span   class='glyphicon glyphicon-remove' aria-hidden='true'></span></span>"
	        $(".label1").append(html);
			
		})
		$("#myPart").modal('hide');
		removeUser();		
	})
	//分页，首页
	  $("#headPage").click(function(){
	  	page=1;
	  	$("#totalPage").html(page+"/"+totalPage);
	  	requestPage(page);
	  })
	  //分页，尾页
	  $("#endPage").click(function(){
	  	$("#totalPage").html(totalPage+"/"+totalPage);
	  	page=totalPage;
	  	requestPage(page);
	  })
	  //分页，上一页
	  $("#prevPage").click(function(){
	  	if(page<=1)
	  	{
	  		page=1;
	  	}
	  	else
	  	{
	  		page=page-1;
	  		$("#totalPage").html(page+"/"+totalPage);
	  		requestPage(page);
	  	}

	 })
	  //分页，下一页
	   $("#nextPage").click(function(){  
	  	if(page>=totalPage)
	  	{
	  		page=page-1;  		
	  	}
	  	else
	  	{
	  		page=page+1;
	  		$("#totalPage").html(page+"/"+totalPage);
	  		requestPage(page);
	  	}
	  	return false;
	  	
	  });
  //提交
   $(document).on("click",".insert",function(){
	   insertid=$(this).attr("data-id");
	   $("#Mymodal").modal('show');    	
   });
  //提交模态框按钮
  $(document).on("click","#btnSure",function(){		
	  requestSure(insertid);//调用提交方法;
  })

//分页
function requestPage(page)
  {$("#tablebody").html("");
	 if(information!=null){
		 information.currentPage=page;
		 var url="ReCheckFilter/reCheckList.do";//地址----------------------------------
		  YuXi.util.get(url,information,function(data){
			  	page=data.currentPage;
				totalPage=data.totalPage;
				$("#totalPage").html(page+"/"+totalPage);
				object=data.list;
			  	$("#tablebody").html("");		
			  	setData(object);
				
			},function(){
			});
	 }
	 else{
		 var dapage={currentPage:page};
			var url="ReCheckFilter/reCheckList.do";
			/*------*/								
			YuXi.util.get(url,dapage,function(data){
				page=data.currentPage;
				totalPage=data.totalPage;
				$("#totalPage").html(page+"/"+totalPage);
				object=data.list;
				setData(object);
			 },function(){
			 })
	 }
}
//删除按钮点击后
	$(document).on("click",".delete",function(){
		deleteid=$(this).attr("data-id");
		  alert(deleteid);
		  $("#delemodal").modal('show');	
	})
//删除模态框确认
$("#dele").click(function(){
	  requestDele(deleteid);
})
  //跳转到修改页面
  $(".update").click(function(){
	  var id= $(this).attr("data-id");
		window.location.href='reUpdateTrial.jsp?update='+id;
  })
 
  
 //即时任务派遣
  $(document).on("click",".nowTask",function(){
	  chooseId=$(this).attr("data-id");
	  $("#tasking").modal("show");
  })
//删除确认
function requestDele(id)
{
		var url="userDelInformationById.do"//删除信息地址;
			 
			  YuXi.util.get(url,{id:id},function(data){
				  if(data.status)
				  {
					  $("#successmodel").modal('show');
					  setTimeout(function(){
						  window.location.reload();
					  },1500);
				  }
				  else
				  {
					  $("#badmodal").modal('show');
				  }
			  },function(){
				  $("#badmodal").modal('show');
			  })
}
//提交按钮
function requestSure(id){
	 
	  var url="CheckFilter/SubToCheck.do";//提交的地址
	  YuXi.util.get(url,{infoId:id},function(data){
		  if(data.status)
		  {
			  $("#successmodel").modal('show');
		  }
		  else
		  {
			 
			  $("#badmodal").modal('show');
		  }
	  },function(){
		  $("#badmodal").modal('show');
	  })
}

//向后台请求已提交的信息数据
function requestRefer()
{	
	/*object=[
  	          {id:1,informationProfile:"待复核xssdsdsdadas",informationPerson:"xxx，xxx，xxxx",time:"2016-07-01"},
  	          {id:3,informationProfile:"待复核的撒到我的撒到我的撒到我的撒到我",informationPerson:"xxx，xxx，xxxx",time:"2016-07-01"},
  	          {id:5,informationProfile:"待复核xssdsdsdadas",informationPerson:"xxx，xxx，xxxx",time:"2016-07-01"},
  	          {id:6,informationProfile:"待复核xssdsdsdadas",informationPerson:"xxx，xxx，xxxx",time:"2016-07-01"},
  	          {id:9,informationProfile:"待复核的撒到我",informationPerson:"xxx，xxx，xxxx",time:"2016-07-01"},
  	          {id:10,informationProfile:"xssdsdsdadas",informationPerson:"xxx，xxx，xxxx",time:"2016-07-01"}
  	       ];
for(var i=0;i<object.length;i++)
{
	informationAddToHtml(object[i]);
}*/


	var url="ReCheckFilter/reCheckList.do";
	YuXi.util.get(url,"null",function(data){
		object=data.list;
		
		setData(object);
		page=data.currentPage;
		totalPage=data.totalPage;
		$("#totalPage").html(page+"/"+totalPage);
	},function(){});
}
//时间段查询
function  requestTime()
{
/*	var information={};
	//起始时间
	var start=$("#valStart").val();
	var end=$("#valEnd").val();
	var array=[];
	array=YuXi.timestamp.get(start,end,null);
	information.starttimestamp=array[0];
	information.endtimestamp=array[1];
	alert(JSON.stringify(information));*/
	
	//时间段查询
	var url="ReCheckFilter/reCheckList.do";
	 YuXi.util.get(url,information,function(data){
		 	object=data.list;
			setData(object);
			page=data.currentPage;
			totalPage=data.totalPage;
			$("#totalPage").html(page+"/"+totalPage);
	 },function(){
	 })
	
}
//简介，分级，渠道，状态，时间（今天,一周...）查找
function firstSearch()
{ 
	//****************************************12.10*****************************
	information={};
	//****************************************12.10*****************************
	if($("#profile").val()!=null&&$("#profile").val()!="")
		information.key=$("#profile").val();//简介
	var curFlowText=$(".state option:selected").val();
	curFlowText==null?"":information.curFLow=curFlowText;//当前状态
	if($(".reSearchSourceSel option:selected").val()!="null"&&$(".reSearchSourceSel option:selected").val()!="")
		information.informationSource=$(".reSearchSourceSel").select2('val').join(",");//来源渠道
	if($(".pes option:selected").val()!="null"&&$(".pes option:selected").val()!="")
		information.informationLv=$(".pes option:selected").val();//分级
	var value=$(".valTime option:selected").val();
	var array=[];
	array=YuXi.timestamp.get(null,null,value);	
	information.startTimestamp=array[0];
	information.endTimestamp=array[1];
	//查询数据传送给后台
	 var url="ReCheckFilter/reCheckList.do";//地址----------------------------------
	  YuXi.util.get(url,information,function(data){
	  		totalPage=data.totalPage;
	  		$("#totalPage").html("1/"+totalPage);
		  	var object=data.list;
		  	page=data.currentPage;
			totalPage=data.totalPage;
			$("#totalPage").html(page+"/"+totalPage);
		  	$("#tablebody").html("");
		
		  	setData(object);
			
		},function(){
		});
}
$("#sub").click(function(){
	var overTime=$("#overTime").val();
	var time=new Date(Date.parse(overTime.replace(/-/g, "/")));
	var idStr="";
	var nameStr="";
	var span=$(".label1").children("span");
	for(var i=0;i<span.length;i++){
		var name=span.eq(i).children("span").eq(1).html();
		var id=span.eq(i).children("span").eq(1).attr("data-id")
		idStr=id+","+idStr;
		nameStr=name+","+nameStr;
	}
	var note=$("#note").val();
	if(overTime==null||overTime==""||overTime==null||overTime==""||span.length==0){
		alert("信息不能为空");
		return false;
	}
	else{
		var url="FistCheckFilter/inputLiable.do";
		var args={informationId:chooseId,overTime:time.getTime(),remark:note,personLiableId:idStr,perSonLiableName:nameStr};
		YuXi.util.get(url,args,function(data){
			if(data.status){
				$("#successmodel").modal("show");
				setTimeout(function(){
					window.location.reload();
				},1000);
			}
			else{
				$("#badmodal").modal("show");
			}
		})
	}
});
function setData(object){
	//模拟数据
	for(var i=0;i<object.length;i++)
	{	
		var pname= object[i].inputPerSonNames;
		pname=pname.substr(1);
		pname=pname.substring(0,pname.length-1);
		object[i].inputPerSonNames=pname;
		var time=YuXi.getTime.get(object[i].createTime);
		if( object[i].informationProfile.length>15)
			object[i].informationProfile= object[i].informationProfile.substring(0,15)+"...";
		var html="<tr><td> "+object[i].id+"</td><td >"+object[i].informationProfile+"</td>"+
		"<td >"+object[i].inputPerSonNames+"</td><td >"+time+"</td>"+
		"<td><a data-id="+object[i].id+" href='javascript:void(0)'; class='detail'>详情</a> &nbsp;&nbsp;<a data-id="+object[i].id+" href='javascript:void(0);' class='update'>修改</a>&nbsp;&nbsp;<a data-id="+object[i].id+" href='javascript:void(0);' class='delete'>结束</a>&nbsp;&nbsp;<a data-id="+object[i].id+" href='javascript:void(0);' class='nowTask'>即时任务派遣</a>&nbsp;&nbsp;<a data-id="+object[i].id+" href='javascript:void(0);' class='insert'>提交</a></td></tr>";
		$("#tablebody").append(html);	
	}		
}
})